const zmq = require("zeromq")
async function startPub() {
    const sock = new zmq.Publisher();
    await sock.bind("tcp://0.0.0.0:22222");
    console.log("Publisher bound to port 22222")
    globalThis.zmq = sock;

    //   while (true) {
    //     console.log("sending a multipart message envelope")
    //     await sock.send(["dnet", "dnet:864"])
    //     await new Promise(resolve => {
    //       setTimeout(resolve, 2000)
    //     })
    //   }
}
module.exports = startPub;
// async function startSub() {
//   const sock = new zmq.Subscriber()

//   sock.connect("tcp://127.0.0.1:22222")
//   sock.subscribe("dcloud")
//   console.log("Subscriber connected to port 22222")

//   for await (let [topic, msg] of sock) {
//     // 把topic和msg转化为UTF8输出
//     topic = topic.toString("utf8")
//     msg = msg.toString("utf8")
//     console.log(
//       "received a message related to:",
//       topic,
//       "containing message:",
//       msg,
//     )
//   }
// }


// startPub()
// setTimeout(startSub, 1000);